﻿using System;
using System.Windows.Input;
using Socium.Domain.Tests.Sociometric;
using Socium.Presentation;

namespace Socium.Tests.Procedures {
	class ProcedureLineItem : ViewModelBase {
		readonly Procedure _procedure;

		public ProcedureLineItem(Procedure procedure) {
			_procedure = procedure;
			
			EditCommand = new Command(OnEdit);
			DeleteCommand = new Command(OnDelete);

			Update();
		}

		string _name;
		public string Name {
			get { return _name; }
			set {
				_name = value;
				OnPropertyChanged("Name");
			}
		}

		public void Update() {
			Name = _procedure.Name;
		}

		public bool Update(Procedure procedure) {
			if (procedure == _procedure) {
				Update();
				return true;
			}

			return false;
		}

		#region Edit

		public ICommand EditCommand { get; private set; }

		public event Action<ProcedureLineItem, Procedure> Edit;

		void OnEdit() {
			var handler = Edit;
			if (handler != null) {
				handler(this, _procedure);
			}
		}

		#endregion

		#region Delete

		public ICommand DeleteCommand { get; private set; }

		public event Action<ProcedureLineItem, Procedure> Delete;

		void OnDelete() {
			var handler = Delete;
			if (handler != null) {
				handler(this, _procedure);
			}
		}

		#endregion
	}
}
